﻿using FarseerPhysics;
using FarseerPhysics.Collision.Shapes;
using FarseerPhysics.Common;
using FarseerPhysics.Dynamics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GameName1
{
    class Obstacle: GameComponent
    {
        private Texture2D _texture;
        private Vector2 _origin;
        private Vector2 _pixelSize;
        private Vector2 _size;
        private Body _body;

        public Obstacle(Game game, World world, string textureName, Vector2 initialPositionSim)
            : base(game, initialPositionSim, world)
        {
            _texture = Game.Content.Load<Texture2D>(textureName);
            _pixelSize = new Vector2(_texture.Width, _texture.Height);
            _origin = _pixelSize / 2f;
            _size = ConvertUnits.ToSimUnits(_pixelSize);

            _body = new Body(world);
            _body.BodyType = BodyType.Dynamic;

            _body.Position = initialPositionSim;
            PolygonShape box = new PolygonShape(PolygonTools.CreateRectangle(_size.X / 2, _size.Y / 2), 0.3f);
            _body.CreateFixture(box);
            _body.LinearDamping = 3;
            _body.AngularDamping = 3;

        }

        public override void Draw(GameTime gameTime, SpriteBatch batch)
        {
            Vector2 position = ConvertUnits.ToDisplayUnits(_body.Position);
            batch.Draw(_texture, position, null, Color.White,
                _body.Rotation, _origin, 1.0f, SpriteEffects.None, 0f);
        }
    }


}
